V2EX  ›  英汉词典
Enqueued related words: Type Punning, Strict Aliasing

Type Pun

释义 Definition

(编程)类型双关 / 类型“借用”:把一段内存按另一种数据类型来解释或访问(例如用指针强制转换、用 union 等),以复用同一块内存中的比特表示。常见于 C/C++ 的底层编程中;在某些情况下可能触发严格别名(strict aliasing)相关的未定义行为。

发音 Pronunciation (IPA)

/taɪp pʌn/

例句 Examples

I used a union as a type pun to inspect the bytes.
我用 union 做类型双关来查看这些字节。

In performance-critical code, careless type punning can break under compiler optimizations because of strict aliasing rules.
在性能关键的代码里,粗心的类型双关可能会因为严格别名规则而在编译器优化下出错。

词源 Etymology

type 来自希腊语 typos(“印记、模子、类型”)经由拉丁语、法语进入英语;pun(“双关语”)词源不确定,可能与“玩弄词语”有关。合在一起的 type pun 借用了“pun(双关)”的比喻:同一段比特“被当作两种类型来理解”。

相关词 Related Words

文学与作品 Literary Works

  • *ISO/IEC 9899 (C Standard)*(涉及对象表示、有效类型与别名规则的条款常被引用来讨论 type punning)
  • *ISO/IEC 14882 (C++ Standard)*(关于对象表示、别名与转换的规则常用于界定何时构成安全/不安全的 type pun)
  • C++ Core Guidelines(对通过指针/转换进行类型“借用”与相关风险有讨论)
关于   ·   帮助文档   ·   自助推广系统   ·   博客   ·   API   ·   FAQ   ·   Solana   ·   1995 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 13ms · UTC 03:53 · PVG 11:53 · LAX 19:53 · JFK 22:53
♥ Do have faith in what you're doing.